package com.ruoyi.control.controller;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.control.domain.VipAccount;
import com.ruoyi.control.service.VipAccountService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * vip账户表(VipAccount)表控制层
 *
 * @author Jiuchengi
 * @since 2024-12-18 15:08:27
 */
@RestController
@RequestMapping("/control/vipAccount")
public class VipAccountController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private VipAccountService vipAccountService;

    /**
     * 分页查询
     *
     * @param vipAccount  筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    public TableDataInfo queryByPage(VipAccount vipAccount) {
        startPage();
        List<VipAccount> list = vipAccountService.queryByPage(vipAccount);
        return getDataTable(list);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public AjaxResult queryById(@PathVariable("id") Long id) {
        return success(this.vipAccountService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param vipAccount 实体
     * @return 新增结果
     */
    @PostMapping
    public AjaxResult add(@Validated @RequestBody VipAccount vipAccount) {
        return toAjax(this.vipAccountService.insert(vipAccount));
    }

    /**
     * 编辑数据
     *
     * @param vipAccount 实体
     * @return 编辑结果
     */
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody VipAccount vipAccount) {
        return toAjax(this.vipAccountService.update(vipAccount));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/{id}")
    public AjaxResult deleteById(@PathVariable Long id) {
        return AjaxResult.success(this.vipAccountService.deleteById(id));
    }

}

